# -*- coding: utf-8 -*-
"""
Created on Thu Jun  3 19:23:13 2021

@author: 17140
"""

import pandas as pd
from sklearn.ensemble import IsolationForest

df = pd.read_csv('forest1525445100350603264.csv')
df.head(200)
model=IsolationForest(n_estimators=10, max_samples='auto', contamination=float(0.1),max_features=1.0)
model.fit(df[['mem']])
df['scores']=model.decision_function(df[['mem']])
df['anomaly']=model.predict(df[['mem']])
df.head(200)



anomaly=df.loc[df['anomaly']==-1]
anomaly_index=list(anomaly.index)
print(anomaly)
outliers_counter = len(df[df['mem'] > 90])
outliers_counter

print("找到异常的准确度:", 100*list(df['anomaly']).count(-1)/(outliers_counter))